<template>
  <div>
    <el-table v-loading="loading" :data="priceLogList">
      <el-table-column label="编号" align="center" prop="id" />
      <el-table-column label="商品编号" align="center" prop="goodsId" />
      <el-table-column label="平台" align="center" prop="platform" :formatter="platformFormat" />
      <el-table-column label="价格" align="center" prop="price" />
      <el-table-column label="状态" align="center" prop="status">
        <template v-slot="scope">
          <el-tag type="success" v-if="scope.row.status === 1">最新</el-tag>
          <el-tag type="info" v-else>历史</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="创建人" align="center" prop="createBy" />
      <el-table-column label="创建时间" align="center" prop="createTime" />
    </el-table>
  </div>
</template>

<script>
import {listPriceLog} from "@/api/recovery/priceLog"
export default {
  name: "price-log",
  props: {
    goodsId: String
  },
  data() {
    return{
      // 遮罩层
      loading: true,
      priceLogList: [],
      queryParams: {
        goodsId: null,
        status: 1
      }
    }
  },
  mounted() {
    this.queryParams.goodsId = this.goodsId;
    this.getPriceLogList();
  },
  created() {
    this.getDicts("sale_price_log_platform").then(response => {
      this.platformOptions = response.data;
      this.loading = false;
    });
  },
  methods: {
    // 平台字典翻译
    platformFormat(row, column) {
      return this.selectDictLabel(this.platformOptions, row.platform);
    },
    getPriceLogList() {
      console.log("执行")
      listPriceLog(this.queryParams).then(res => {
        this.priceLogList = res.rows;
      })
    }
  },
  watch: {
    goodsId(n, o) {
      this.queryParams.goodsId = n;
      this.getPriceLogList();
    }
  }
}
</script>

<style scoped>

</style>
